#include "matrix_float.h"

//private
void matrix_float::create_matrix(int r, int c){
	if (r != 0 && c != 0){
		r_size = r;
		c_size = c;
		*mptr = new float[r_size];
		for (int i = 0; i < r; i++){
			mptr[i] = new float[c_size];
		}
	}
	else{
		r_size = 0;
		c_size = 0;
		*mptr = nullptr;
	}
}

void matrix_float::delete_matrix(){
	for (int i = 0; i < r_size; i++){
		delete mptr[i];
	}
	delete []*mptr;
	*mptr = nullptr;
}

//public
matrix_float::matrix_float()
{
	create_matrix(0, 0);
}

matrix_float::matrix_float(int r, int c)
{
	create_matrix(r, c);
}


matrix_float::~matrix_float()
{
	delete_matrix();
}

void matrix_float::read_from_keyboard(){
	for (int i = 0; i < r_size; i++){
		for (int j = 0; j < c_size; j++){
			cout << "Insert value (" << j + 1 << "/" << c_size << ")" << " on row (" << i + 1 << "/" << r_size << "): ";
			cin >> mptr[i][j];
		}
	}
}

void matrix_float::print(){
	for (int i = 0; i < r_size; i++){
		for (int j = 0; j < c_size; j++){
			cout << mptr[i][j] << " ";
		}
		cout << endl;
	}
}